class ArticlesController < ApplicationController
before_filter :authorize
    layout "websitearticles"

      active_scaffold :article do |config|
  config.label = "Articles"
#  config.action_links.add 'export_csv', :label => 'Export to Excel', :page => true 
  config.show.link.label = "Show Detail"  
  config.show.link.type = :record
  config.show.link.inline = true
  config.show.link.position = :after 
  
 	  config.columns[:published].inplace_edit = true
 	  
	  config.columns[:websitesinf].form_ui = :select 
    config.columns[:websitesinf].label = 'Websites Copy To' 	  
    config.columns[:user_published_by].label = 'Alias' 	  
	  config.columns[:tag].form_ui = :select 
	  config.columns[:categoryt].form_ui = :select 	     
	  config.columns[:category].form_ui = :select  
	  
    config.columns[:category].label = 'Category 1' 	
    config.columns[:categoryt].label = 'Category 2' 	    	  
	  
    config.columns[:synopsis].form_ui = :textarea
    config.columns[:synopsis].options = {:rows => 60, :cols => 100}

# config.columns[:original_link].options = {:size => 80}
    config.columns[:body].form_ui = :textarea
    config.columns[:body].options = {:rows => 60, :cols => 100}
    
    config.columns[:published].form_ui = :checkbox    
#    config.columns[:published].inplace_edit = true
	  config.columns = [:websitesinf,:title,:synopsis,:body,:category,:categoryt,:body,:tag,:created_by,:created_at,:published,:published_at,:last_accessed_at,:imageurl,:original_link,:last_accessed_user,:last_updated_at,:last_updated_user,:user_published_by]
    config.list.columns.exclude :imageurl,:body,:original_link,:websitesinf,:last_accessed_user,:last_updated_at,:last_updated_user,:last_accessed_at,:created_by,:created_at,:published,:published_at,:category,:categoryt,:tag

#    config.action_links.add 'mytest', :label => 'Websites', :type => :record, :page => true
		config.action_links.add 'mytest1', :label => 'Photos', :type => :record, :page => true
		config.action_links.add 'mytest2', :label => 'New Tag', :type => :record, :page => true

    config.create.columns.exclude(:synopsis,:body,:created_at,:created_by,:published_at,:last_accessed_at,:last_accessed_user,:last_updated_at,:last_updated_user)  
    config.create.columns.add_subgroup "Detail Information"  do |group|       
       	group.add(:synopsis,:body) 
       	end     
       	
    config.update.columns.exclude(:websitesinf,:synopsis,:body,:created_by,:created_at,:published_at,:last_accessed_at,:last_accessed_user,:last_updated_at,:last_updated_user)  
    config.update.columns.add_subgroup "Detail Information"  do |group|       
    	group.add(:synopsis,:body)  
    	end  

    config.show.columns.exclude(:websitesinf,:synopsis,:title,:tag,:created_by,:created_at,:published,:published_at,:last_accessed_at,:last_accessed_user,:last_updated_at,:last_updated_user,:user_published_by)       	
  config.show.label = "Show Detail"

  end
  
  def show
    super

    @article = Article.find(params[:id])
    @article.last_accessed_user = User.find(session[:user_id]).name
    @article.last_accessed_at = Time.now
    @article.save

  end

	def after_create_save(record); 
		  record.websitesinf_id = params[:websiteid]
	    record.save
	    
	    if   params[:record][:websitesinf]
         params[:record][:websitesinf][':id'].each do |websid|
				   @newcopy = Article.new(:title=>record.title,:synopsis=>record.synopsis,:body=>record.body,:websitesinf_id=>websid.to_i)
							    
				   @newcopy.save

  	     end

      end
	
#    @websitesinf = Websitesinf.find(params[:websiteid])

#    unless @websitesinf.has_article?(record.title)
#      @websitesinf.articles << record
#    end

	end
	


  def update

    super
   @mytest = params[:record][:user_published_by]
    @article = Article.find(params[:id])
     @article.user_published_by = @mytest     
    @article.last_updated_user = User.find(session[:user_id]).name
    @article.last_updated_at = Time.now
    @article.save

  end 
  

  
  def mytest
  @all_websitesinfs = Websitesinf.find(:all)
    @article = Article.find(params[:id])
  end
  
    def mytest1
   redirect_to article_photos_path(:article_id => params[:id])
  end
  
      def mytest2
   redirect_to :controller =>'article_tags',:action=>'index',:article_id => params[:id],:websiteid=>params[:websiteid]

  end

end
